package com.fare.taluo.util;

import java.util.ArrayList;
import java.util.List;

import com.fare.taluo.vo.airfreight.StopOverEntityVO;
import com.fare.taluo.vo.airfreight.doub.CabinRelationEntityVO;
import com.fare.taluo.vo.core.AgentInfo;
import com.fare.taluo.vo.core.CabinEntityVO;
import com.fare.taluo.vo.core.PlaneInfo;
import com.fare.taluo.vo.core.TransitchangeEntityVO;
import com.fare.taluo.vo.doub.CabinRelationVO;
import com.fare.taluo.vo.doub.DoublePlaneInfoVO;
import com.fare.taluo.vo.doub.ReturnAgentVO;
import com.fare.taluo.vo.doub.ReturnCabinVO;
import com.fare.taluo.vo.doub.ReturnDoublePlaneInfoVO;
import com.fare.taluo.vo.doub.ReturnStopOverVO;
import com.fare.taluo.vo.doub.ReturnTransitVO;
import com.fare.taluo.vo.single.AgentVO;
import com.fare.taluo.vo.single.CabinVO;
import com.fare.taluo.vo.single.SinglePlaneInfoVO;
import com.fare.taluo.vo.single.StopOverVO;
import com.fare.taluo.vo.single.TransitVO;

public class PlaneInfoVOToPlaneInfo {
	
	public static PlaneInfo singleToPlanInfo(SinglePlaneInfoVO vo){
		PlaneInfo planeInfo=new PlaneInfo();
		planeInfo.setActuallyFlightNo(vo.getActuallyFlightNo());
		planeInfo.setAgentName(vo.getAgentName());
		planeInfo.setAreaCode(vo.getAreaCode());
		planeInfo.setAreaName(vo.getAgentName());
		planeInfo.setGrabChannelNum(vo.getAttachHbaseKey());
		planeInfo.setCarrierFullName(vo.getCarrierFullName());
		planeInfo.setCarrierKey(vo.getCarrierKey());
		planeInfo.setCarrierName(vo.getCarrierName());
		planeInfo.setGrapDate(vo.getGrabDate());
		planeInfo.setGrabDate(DateUtils.dateToStr(vo.getGrabDate(), "yyyyMMddHHmmssSSS"));
		planeInfo.setFlightBatchEndTime(DateUtils.dateToStr(vo.getEndTime(), "yyyyMMddHHmmssSSS"));
		planeInfo.setFlightBatchDate(vo.getFlightDate());
		planeInfo.setFlightId(vo.getFlightNo());
		planeInfo.setType(vo.getFlightType());
		planeInfo.setFromCity(vo.getFromCity());
		planeInfo.setFromCityName(vo.getFromCityName());
		planeInfo.setGrabChannelId(vo.getGrabChannelId().toString());
		planeInfo.setGrabChannel(vo.getGrabChannelName());
		planeInfo.setId(vo.getId().toString());
		planeInfo.setSOURCE_ROWKEY(vo.getSourceRowkey());
		planeInfo.setFlightBatchStartTime(DateUtils.dateToStr(vo.getStartTime(), "yyyyMMddHHmmssSSS"));
		planeInfo.setToCity(vo.getToCity());
		planeInfo.setToCityName(vo.getToCityName());
		planeInfo.setHighPrice(vo.getTotalHighestPrice().toString());
		planeInfo.setLowprPrice(vo.getTotalLowestPrice().toString());
		if(null!=vo.getAgents() && vo.getAgents().size()>0){
			List<AgentInfo> agentInfos = new ArrayList<AgentInfo>();
			for(AgentVO agentVo: vo.getAgents()){
				AgentInfo agentInfo =PlaneInfoVOToPlaneInfo.changeToAgentEntityVO(agentVo);
				agentInfos.add(agentInfo);
			}
			planeInfo.setAgentInfos(agentInfos);
		}
		if(null!=vo.getCabins() && vo.getCabins().size()>0){
			List<CabinEntityVO> cabins =new ArrayList<CabinEntityVO>();
			for(CabinVO cabinVo :vo.getCabins()){
				CabinEntityVO cabinEntityVO =PlaneInfoVOToPlaneInfo.changeToCabinEntityVO(cabinVo);
				cabins.add(cabinEntityVO);
			}
			planeInfo.setCabins(cabins);
		}
		if(null!=vo.getStopOvers()&& vo.getStopOvers().size()>0){
			List<StopOverEntityVO> stopOverlist =new ArrayList<StopOverEntityVO>();
			for(StopOverVO stopOverVo :vo.getStopOvers()){
				StopOverEntityVO stopOverEntityVO =PlaneInfoVOToPlaneInfo.changeToStopOverEntityVO(stopOverVo);
				stopOverlist.add(stopOverEntityVO);
			}
			planeInfo.setStopOverlist(stopOverlist);
		}
		if(null!=vo.getTransits() && vo.getTransits().size()>0){
			List<TransitchangeEntityVO> transit =new ArrayList<TransitchangeEntityVO>();
			for(TransitVO transitVO :vo.getTransits()){
				TransitchangeEntityVO transitchangeEntityVO =PlaneInfoVOToPlaneInfo.changeToTransitchangeEntityVO(transitVO);
				transit.add(transitchangeEntityVO);
			}
			planeInfo.setTransit(transit);
		}
		if(null!=planeInfo && null!=planeInfo.getFlightId()){
			return planeInfo;
		}
		return null;
	}

	private static TransitchangeEntityVO changeToTransitchangeEntityVO(
			TransitVO vo) {
		TransitchangeEntityVO transit =new TransitchangeEntityVO();
		transit.setActuallyFlightNo(vo.getActuallyFlightNo());
		transit.setCarrierFullName(vo.getCarrierFullName());
		transit.setCarrierKey(vo.getCarrierKey());
		transit.setCarrierName(vo.getCarrierName());
		transit.setEndTime(null==vo.getEndTime()? null:DateUtils.dateToStr(vo.getEndTime(), "yyyyMMddHHmmssSSS"));
		transit.setFlightNo(vo.getFlightNo());
		//transit.setFlightTime(vo.get);
		transit.setFlightType(vo.getFlightType());
	//	transit.setFlightTyte(vo.getF)
		transit.setFromAir(vo.getFromAirPort());
		transit.setFromAirPort(vo.getFromAirPort());
		transit.setFromAirPortName(vo.getFromAirPortName());
		//transit.setFromCity(vo.getF);
	//	transit.setFromCityCode(fromCityCode);
	 // transit.setHightPrice(vo.get)
	//	transit.setLowerPrice(vo.getT);
		transit.setStartTime(null==vo.getStartTime()?null:DateUtils.dateToStr(vo.getStartTime(), "yyyyMMddHHmmssSSS"));
		transit.setStayTime(vo.getStayTime().toString());
		transit.setToAir(vo.getToAirPort());
		transit.setToAirPort(vo.getToAirPort());
		transit.setToAirPortName(vo.getToAirPortName());
	//	transit.setTransitCarrierKey(vo.getT)
		return transit;
	}

	private static StopOverEntityVO changeToStopOverEntityVO(
			StopOverVO vo) {
		StopOverEntityVO stop =new StopOverEntityVO();
		stop.setArrTime(null==vo.getArrTime()?null:DateUtils.dateToStr(vo.getArrTime(), "yyyyMMddHHmmssSSS") );
		stop.setLeaveTime(null==vo.getLeaveTime()?null:DateUtils.dateToStr(vo.getLeaveTime(), "yyyyMMddHHmmssSSS"));
		stop.setStayTime(vo.getStayTime().toString());
		stop.setStopCity(vo.getStopCity());
		return stop;
	}

	private static CabinEntityVO changeToCabinEntityVO(CabinVO vo) {
		CabinEntityVO cabin =new CabinEntityVO();
		cabin.setBackCash(vo.getBackCash());
		cabin.setCabinName(vo.getSubCabinName());
		//cabin.setCabinNo(vo.get);
		//cabin.setCabinRebate(vo.getRebate());
		//cabin.setCabinServer(vo.get);
		cabin.setCabinType(vo.getCabinType());
		cabin.setLastSeatInfo(vo.getLastSeatInfo());
		//cabin.setLever(vo.get)
		cabin.setMileageRatio(vo.getMileageRatio());
		cabin.setOriginalPrice(vo.getOriginalPrice());
		cabin.setPrice(vo.getPrice());
		cabin.setProductName(vo.getProductName());
		cabin.setRebate(vo.getRebate());
		cabin.setSubCabinName(vo.getSubCabinName());
		cabin.setTuigaiqian(vo.getTuigaiqian());
		cabin.setZhijian(vo.getZhijian());
		return cabin;
	}

	private static AgentInfo changeToAgentEntityVO(AgentVO agentVo) {
		AgentInfo agentInfo =new AgentInfo();
		agentInfo.setAddress(agentVo.getAddress());
		agentInfo.setCname(agentVo.getCompanyName());
		agentInfo.setName(agentVo.getName());
		agentInfo.setOriginalPrice(agentVo.getOriginalPrice().toString());
		agentInfo.setPrice(agentVo.getPrice().toString());
		return agentInfo;
	}
	
	public static PlaneInfo doubleToPlaneInfo(DoublePlaneInfoVO vo){
		PlaneInfo planeInfo=new PlaneInfo();
		planeInfo.setActuallyFlightNo(vo.getActuallyFlightNo());
		planeInfo.setAgentName(vo.getAgentName());
		planeInfo.setAreaCode(vo.getAreaCode());
		planeInfo.setAreaName(vo.getAgentName());
		planeInfo.setGrabChannelNum(vo.getAttachHbaseKey());
		planeInfo.setCarrierFullName(vo.getCarrierFullName());
		planeInfo.setCarrierKey(vo.getCarrierKey());
		planeInfo.setCarrierName(vo.getCarrierName());
		planeInfo.setGrapDate(vo.getGrabDate());
		planeInfo.setGrabDate(null==vo.getGrabDate()? null:DateUtils.dateToStr(vo.getGrabDate(), "yyyyMMddHHmmssSSS"));
		planeInfo.setFlightBatchEndTime(null==vo.getEndTime() ? null :DateUtils.dateToStr(vo.getEndTime(), "yyyyMMddHHmmssSSS"));
		planeInfo.setFlightBatchDate(vo.getFlightDate());
		planeInfo.setFlightId(vo.getFlightNo());
		planeInfo.setType(vo.getFlightType());
		planeInfo.setFromCity(vo.getFromCity());
		planeInfo.setFromCityName(vo.getFromCityName());
		planeInfo.setGrabChannelId(vo.getGrabChannelId().toString());
		planeInfo.setGrabChannel(vo.getGrabChannelName());
		planeInfo.setId(vo.getId().toString());
		planeInfo.setSOURCE_ROWKEY(vo.getSourceRowkey());
		planeInfo.setFlightBatchStartTime(null==vo.getStartTime() ? null :DateUtils.dateToStr(vo.getStartTime(), "yyyyMMddHHmmssSSS"));
		planeInfo.setToCity(vo.getToCity());
		planeInfo.setToCityName(vo.getToCityName());
		planeInfo.setHighPrice(vo.getTotalHighestPrice().toString());
		planeInfo.setLowprPrice(vo.getTotalLowestPrice().toString());
		if(null!=vo.getAgents() && vo.getAgents().size()>0){
			List<AgentInfo> agentInfos = new ArrayList<AgentInfo>();
			for(AgentVO agentVo: vo.getAgents()){
				AgentInfo agentInfo =PlaneInfoVOToPlaneInfo.changeToAgentEntityVO(agentVo);
				agentInfos.add(agentInfo);
			}
			planeInfo.setAgentInfos(agentInfos);
		}
		if(null!=vo.getCabins() && vo.getCabins().size()>0){
			List<CabinEntityVO> cabins =new ArrayList<CabinEntityVO>();
			for(CabinVO cabinVo :vo.getCabins()){
				CabinEntityVO cabinEntityVO =PlaneInfoVOToPlaneInfo.changeToCabinEntityVO(cabinVo);
				cabins.add(cabinEntityVO);
			}
			planeInfo.setCabins(cabins);
		}
		if(null!=vo.getStopOvers()&& vo.getStopOvers().size()>0){
			List<StopOverEntityVO> stopOverlist =new ArrayList<StopOverEntityVO>();
			for(StopOverVO stopOverVo :vo.getStopOvers()){
				StopOverEntityVO stopOverEntityVO =PlaneInfoVOToPlaneInfo.changeToStopOverEntityVO(stopOverVo);
				stopOverlist.add(stopOverEntityVO);
			}
			planeInfo.setStopOverlist(stopOverlist);
		}
		if(null!=vo.getTransits() && vo.getTransits().size()>0){
			List<TransitchangeEntityVO> transit =new ArrayList<TransitchangeEntityVO>();
			for(TransitVO transitVO :vo.getTransits()){
				TransitchangeEntityVO transitchangeEntityVO =PlaneInfoVOToPlaneInfo.changeToTransitchangeEntityVO(transitVO);
				transit.add(transitchangeEntityVO);
			}
			planeInfo.setTransit(transit);
		}
		if(null!=vo.getCabinRelations() && vo.getCabinRelations().size()>0){
			List<CabinRelationEntityVO> cabinRelations = new ArrayList<CabinRelationEntityVO>();
			for(CabinRelationVO cabinRelationVO :vo.getCabinRelations()){
				CabinRelationEntityVO cabinRelationEntityVO =PlaneInfoVOToPlaneInfo.changeToCabinRelationEntityVO(cabinRelationVO);
				cabinRelations.add(cabinRelationEntityVO);
			}
			planeInfo.setCabinRelations(cabinRelations);
		}
		if(null!=vo.getReturnPlaneInfos() && vo.getReturnPlaneInfos().size()>0){
			List<PlaneInfo> returnPlaneInfo = new ArrayList<PlaneInfo>();
			for(ReturnDoublePlaneInfoVO returnDoublePlaneInfoVO : vo.getReturnPlaneInfos()){
				PlaneInfo returnPlane =PlaneInfoVOToPlaneInfo.changeToReturnPlaneInfo(returnDoublePlaneInfoVO);
				returnPlaneInfo.add(returnPlane);
			}
			planeInfo.setReturnPlaneInfo(returnPlaneInfo);
		}
		if(null!=planeInfo && null!=planeInfo.getFlightId()){
			return planeInfo;
		}
		return null;
	}

	private static PlaneInfo changeToReturnPlaneInfo(
			ReturnDoublePlaneInfoVO vo) {
		PlaneInfo planeInfo=new PlaneInfo();
		planeInfo.setActuallyFlightNo(vo.getActuallyFlightNo());
		planeInfo.setAgentName(vo.getAgentName());
		planeInfo.setAreaCode(vo.getAreaCode());
		planeInfo.setAreaName(vo.getAgentName());
		planeInfo.setGrabChannelNum(vo.getAttachHbaseKey());
		planeInfo.setCarrierFullName(vo.getCarrierFullName());
		planeInfo.setCarrierKey(vo.getCarrierKey());
		planeInfo.setCarrierName(vo.getCarrierName());
		planeInfo.setGrapDate(vo.getCreateTime());
		planeInfo.setGrabDate(null==vo.getCreateTime() ? null :DateUtils.dateToStr(vo.getCreateTime(), "yyyyMMddHHmmssSSS"));
		planeInfo.setFlightBatchEndTime(null ==vo.getEndTime() ?null: DateUtils.dateToStr(vo.getEndTime(), "yyyyMMddHHmmssSSS"));
		planeInfo.setFlightBatchDate(vo.getFlightDate());
		planeInfo.setFlightId(vo.getFlightNo());
		planeInfo.setType(vo.getFlightType());
		planeInfo.setFromCity(vo.getFromCity());
		planeInfo.setFromCityName(vo.getFromCityName());
		planeInfo.setGrabChannelId(vo.getGrabChannelId().toString());
		planeInfo.setGrabChannel(vo.getGrabChannelName());
	//	planeInfo.setId(vo.getId().toString());
		planeInfo.setSOURCE_ROWKEY(vo.getSourceRowkey());
		planeInfo.setFlightBatchStartTime(null==vo.getStartTime() ? null : DateUtils.dateToStr(vo.getStartTime(), "yyyyMMddHHmmssSSS"));
		planeInfo.setToCity(vo.getToCity());
		planeInfo.setToCityName(vo.getToCityName());
		planeInfo.setHighPrice(vo.getTotalHighestPrice().toString());
		planeInfo.setLowprPrice(vo.getTotalLowestPrice().toString());
		if(null!=vo.getReturnAgents() && vo.getReturnAgents().size()>0){
			List<AgentInfo> agentInfos = new ArrayList<AgentInfo>();
			for(ReturnAgentVO agentVo: vo.getReturnAgents()){
				AgentInfo agentInfo =PlaneInfoVOToPlaneInfo.changeToAgentEntityVO(agentVo);
				agentInfos.add(agentInfo);
			}
			planeInfo.setAgentInfos(agentInfos);
		}
		if(null!=vo.getReturnCabins() && vo.getReturnCabins().size()>0){
			List<CabinEntityVO> cabins =new ArrayList<CabinEntityVO>();
			for(ReturnCabinVO cabinVo :vo.getReturnCabins()){
				CabinEntityVO cabinEntityVO =PlaneInfoVOToPlaneInfo.changeToCabinEntityVO(cabinVo);
				cabins.add(cabinEntityVO);
			}
			planeInfo.setCabins(cabins);
		}
		if(null!=vo.getReturnStopOvers()&& vo.getReturnStopOvers().size()>0){
			List<StopOverEntityVO> stopOverlist =new ArrayList<StopOverEntityVO>();
			for(ReturnStopOverVO stopOverVo :vo.getReturnStopOvers()){
				StopOverEntityVO stopOverEntityVO =PlaneInfoVOToPlaneInfo.changeToStopOverEntityVO(stopOverVo);
				stopOverlist.add(stopOverEntityVO);
			}
			planeInfo.setStopOverlist(stopOverlist);
		}
		if(null!=vo.getReturnTransits() && vo.getReturnTransits().size()>0){
			List<TransitchangeEntityVO> transit =new ArrayList<TransitchangeEntityVO>();
			for(ReturnTransitVO transitVO :vo.getReturnTransits()){
				TransitchangeEntityVO transitchangeEntityVO =PlaneInfoVOToPlaneInfo.changeToTransitchangeEntityVO(transitVO);
				transit.add(transitchangeEntityVO);
			}
			planeInfo.setTransit(transit);
		}
		if(null!=planeInfo && null!=planeInfo.getFlightId()){
			return planeInfo;
		}
		return null;
	}

	private static TransitchangeEntityVO changeToTransitchangeEntityVO(
			ReturnTransitVO vo) {
		TransitchangeEntityVO transit =new TransitchangeEntityVO();
		transit.setActuallyFlightNo(vo.getActuallyFlightNo());
		transit.setCarrierFullName(vo.getCarrierFullName());
		transit.setCarrierKey(vo.getCarrierKey());
		transit.setCarrierName(vo.getCarrierName());
		transit.setEndTime(null ==vo.getEndTime()? null : DateUtils.dateToStr(vo.getEndTime(), "yyyyMMddHHmmssSSS"));
		transit.setFlightNo(vo.getFlightNo());
		//transit.setFlightTime(vo.get);
		transit.setFlightType(vo.getFlightType());
	//	transit.setFlightTyte(vo.getF)
		transit.setFromAir(vo.getFromAirPort());
		transit.setFromAirPort(vo.getFromAirPort());
		transit.setFromAirPortName(vo.getFromAirPortName());
		//transit.setFromCity(vo.getF);
	//	transit.setFromCityCode(fromCityCode);
	 // transit.setHightPrice(vo.get)
	//	transit.setLowerPrice(vo.getT);
		transit.setStartTime(null == vo.getStartTime() ? null:DateUtils.dateToStr(vo.getStartTime(), "yyyyMMddHHmmssSSS"));
		transit.setStayTime(vo.getStayTime().toString());
		transit.setToAir(vo.getToAirPort());
		transit.setToAirPort(vo.getToAirPort());
		transit.setToAirPortName(vo.getToAirPortName());
	//	transit.setTransitCarrierKey(vo.getT)
		return transit;
	}

	private static StopOverEntityVO changeToStopOverEntityVO(
			ReturnStopOverVO vo) {
		StopOverEntityVO stop =new StopOverEntityVO();
		stop.setArrTime(null ==vo.getArrTime()?null : DateUtils.dateToStr(vo.getArrTime(), "yyyyMMddHHmmssSSS") );
		stop.setLeaveTime(null ==vo.getLeaveTime() ? null:DateUtils.dateToStr(vo.getLeaveTime(), "yyyyMMddHHmmssSSS"));
		stop.setStayTime(vo.getStayTime().toString());
		stop.setStopCity(vo.getStopCity());
		return stop;
	}

	private static CabinEntityVO changeToCabinEntityVO(ReturnCabinVO vo) {
		CabinEntityVO cabin =new CabinEntityVO();
		cabin.setBackCash(vo.getBackCash());
		cabin.setCabinName(vo.getSubCabinName());
		//cabin.setCabinNo(vo.get);
		//cabin.setCabinRebate(vo.getRebate());
		//cabin.setCabinServer(vo.get);
		cabin.setCabinType(vo.getCabinType());
		cabin.setLastSeatInfo(vo.getLastSeatInfo());
		//cabin.setLever(vo.get)
		cabin.setMileageRatio(vo.getMileageRatio());
		cabin.setOriginalPrice(vo.getOriginalPrice());
		cabin.setPrice(vo.getPrice());
		cabin.setProductName(vo.getProductName());
		cabin.setRebate(vo.getRebate());
		cabin.setSubCabinName(vo.getSubCabinName());
		cabin.setTuigaiqian(vo.getTuigaiqian());
		cabin.setZhijian(vo.getZhijian());
		return cabin;
	}

	private static AgentInfo changeToAgentEntityVO(ReturnAgentVO agentVo) {
		AgentInfo agentInfo =new AgentInfo();
		agentInfo.setAddress(agentVo.getAddress());
		agentInfo.setCname(agentVo.getCompanyName());
		agentInfo.setName(agentVo.getAgentName());
		agentInfo.setOriginalPrice(agentVo.getOriginalPrice().toString());
		agentInfo.setPrice(agentVo.getPrice().toString());
		return agentInfo;
	}

	private static CabinRelationEntityVO changeToCabinRelationEntityVO(
			CabinRelationVO vo) {
		CabinRelationEntityVO cabin =new CabinRelationEntityVO();
		cabin.setCabinId(vo.getCabinId());
		cabin.setFullPrice(vo.getFullPrice().toString());
		cabin.setReturnCabinId(vo.getReturnCabinId());
		return cabin;
	}

}
